package ch6.ex2;

import ch6.ex1.Person;

public class Main {
	public static void main(String[] args) {

		// Person person1 = new Person();
		// Person person2 = new Person();
		// Person person3 = new Person();

		// person1.name = "Kris";
		// person1.age = 31;
		// person2.name = "Mark";
		// person2.age = 32;
		// person3.name = "Tomas";
		// person3.age = 33;

		Person[] persons = { new Person(), new Person(), new Person() };
		persons[0].name = "Kris";
		persons[0].age = 31;
		persons[1].name = "Mark";
		persons[1].age = 32;
		persons[2].name = "Tomas";
		persons[2].age = 33;

		Integer max = 1;
		Integer poz = 0;
		for (Integer idx = 0; idx < persons.length; idx++) {
			if (persons[idx].age > max) {
				max = persons[idx].age;
				poz = idx;

			}

		}

		Person theOldest = null;
		theOldest = findThe(persons);

		System.out.println(theOldest.name);
	}

	static Person findThe(Person[] persons) {

		Person theOldest = new Person();
		theOldest.age = 0;

		for (Person person : persons) {
			theOldest = (person.age > theOldest.age) ? person : theOldest;
		}

		return theOldest;
	}
}
// low capping high cochation
// powiazania spojnosc

// own project, from command line(attributes), name surname age, name sur age,
// name sur age.
// custom class persons. create method greating. static method that creates new
// surname (reversed name)
// do greating again to show
